<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Listship_model extends MY_Model{
	
    public function __construct(){
            parent::__construct();
            $this->table_name = 'book_listship';
    }
    
    public function export($params){
        
            $this->db->select('bs.id AS salesID,bs.name,bs.phone,bs.note_customers,bs.lastupdated,usr.username AS saler,tbl.phone_callstatus,tbl.booker,bl.note AS ghichu,bl.booker AS booker');
            $this->db->from('book_sales AS bs');
            $this->db->join('users AS usr','usr.id = bs.owner');
            $this->db->join($this->table_name.' AS tbl','tbl.saleID = bs.id','left');
            $this->db->join('book_listship AS bl','bl.saleID = bs.id','LEFT');
            $this->db->where('bs.note_customers != ""');
            
            if($params['beginTime']){
                $this->db->where('bs.lastupdated >= '.$params['beginTime']);
            }
            
            if($params['endTime']){
                $this->db->where('bs.lastupdated <= '.$params['endTime']);
            }
            
            $query = $this->db->get();
            //echo $this->db->last_query();exit;
            return $query->result();
    }
     
    public function getListShip($params){
            $this->db->select('bs.id AS salesID,bs.name,bs.phone,bs.note_customers,bs.lastupdated,usr.username AS saler,tbl.phone_callstatus,tbl.booker');
            $this->db->from('book_sales AS bs');
            $this->db->join('users AS usr','usr.id = bs.owner');
            $this->db->join($this->table_name.' AS tbl','tbl.saleID = bs.id','left');
            $this->db->where('bs.note_customers != ""');
            
            if($params['salesID']){
                $this->db->where('bs.id',$params['salesID']);
            }
            if($params['phone']){
                $this->db->where('bs.phone',$params['phone']);
            }
            
            $this->db->where('tbl.booker IS NULL');
            $query = $this->db->get();
            return $query->result();
    }
}